package com.ming.controller;

import com.ming.domain.User;
import com.ming.domain.UserAddr;
import com.ming.sevice.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:何元才
 * @Desc: 会员接口管理
 * @data:2021-04-06 14:52
 */
@RestController
@RequestMapping("/p/user")
@Api(tags = "会员管理接口")
public class MemberController {

    @Autowired
    private UserService userService;

    @PutMapping("setUserInfo")
    @ApiOperation("更新用户信息")
    public ResponseEntity<Void> setUserInfo(@RequestBody User user){
        //1.获取当前用户是谁
        String openId = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
        user.setUserId(openId);
        userService.updateById(user);
        return ResponseEntity.ok().build();
    }

    /**
     * 提供远程调用获取用户集合的方法
     *
     * @param userIds
     * @return
     */
    @PostMapping("getUserList")
    @ApiOperation("提供远程调用获取用户集合的方法")
    List<User> getUserList(@RequestBody List<String> userIds) {
        return userService.listByIds(userIds);
    }

}
